#include "CameraControlProxy.hpp"
#include <fmt/format.h>
#include <filesystem>
#include <stdexcept>

CameraControlProxy::CameraControlProxy()
: queue("/HBTY_MSGSERVER_CAMERACOLLEGE")
{
  if(!std::filesystem::exists("/tmp/HBTY_server_ipc.yaml"))
    throw std::runtime_error("无法获取采集模块状态");
  collegeNode=YAML::LoadFile("/tmp/HBTY_server_ipc.yaml");
  if(!(collegeNode["shm_size"] && collegeNode["num"] && collegeNode["shm"]))
    throw std::runtime_error("采集数据文件结构错误");
}

CameraControlProxy::~CameraControlProxy()
{
}

void CameraControlProxy::StartRecord(std::string savepath)
{
  queue.call<void>(fmt::format("Record Start {}",savepath));
}

void CameraControlProxy::StopRecord()
{
  queue.call<void>("Record Stop");
}

void CameraControlProxy::StartMonitor()
{
  queue.call<void>("Monitor Start");
}

void CameraControlProxy::StopMonitor()
{
  queue.call<void>("Monitor Stop");
}

bool CameraControlProxy::RecordStatus()
{
  return queue.call<bool>("Status Record");
}

bool CameraControlProxy::MonitorStatus()
{
  return queue.call<bool>("Status Monitor");
}

std::vector<std::string> CameraControlProxy::GetShareMemList()
{
  std::vector<std::string> list;
  long num=collegeNode["num"].as<long>();
  list.reserve(num);
  YAML::Node idlist=collegeNode["shm"];
  for(int i=0;i<num;i++)
    list.push_back(idlist[i].as<std::string>());
  return list;
}

long CameraControlProxy::GetShareMemSize()
{
  return collegeNode["shm_size"].as<long>();
}
